﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NeuralNetworkComponents
{
    public abstract class Neuron
    {

        public Double[] Weights { get; set; }
        public Int32 InputsCount { get; protected set; }
        public Double Output { get; protected set; }

        protected static Random Randomizer { get; set; } 
        protected static DoubleRange RandRange { get; set; }

        public Double this[int index]
        {
            get { return Weights[index]; }
            set { Weights[index] = value; }
        }

        public Neuron(int inputs)
        {
            Randomizer = new Random((int)DateTime.Now.Ticks);
            RandRange = new DoubleRange(0.0, 1.0);

            InputsCount = Math.Max(1, inputs);
            Weights = new Double[InputsCount];
            Randomize();
        }

        public virtual void Randomize()
        {
            Double d = RandRange.Length;

            for (int i = 0; i < InputsCount; i++)
                Weights[i] = Randomizer.NextDouble() * d + RandRange.Min;
        }

        public abstract double Compute(double[] input);
        
    }
}
